package org.cug.service.impl;

import org.cug.mapper.CoursedesignMapper;
import org.cug.mapper.UserMapper;
import org.cug.pojo.CourseDesign;
import org.cug.pojo.User;
import org.cug.service.CoursedesignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CoursedesignSevrviceimpl implements CoursedesignService {
    @Autowired
    private CoursedesignMapper coursedesignMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<CourseDesign> list(Integer userId, Short semester) {
        User user =userMapper.getrole(userId);
        List<Integer> ids=new ArrayList<>();
        if(user.getRole().equals("1")){
            ids.add(userId);
        }
        else if(user.getRole().equals("2")){
            ids = userMapper.getusers(user.getDepartment());
        }else if(user.getRole().equals("3")){
            ids = userMapper.getuserscol(user.getCollege());
        }else {
            List<CourseDesign> coursedesigns=coursedesignMapper.listall(semester);
            return coursedesigns;
        }
        List<CourseDesign> coursedesigns=coursedesignMapper.list(ids,semester);
        return coursedesigns;
    }

    @Override
    public void add(CourseDesign coursedesign) {
        coursedesignMapper.insert(coursedesign);
    }

    @Override
    public void delete(List<Integer> ids) {
        coursedesignMapper.delete(ids);
    }

    @Override
    public CourseDesign selectid(Integer id) {
        return coursedesignMapper.selectid(id);
    }
    //通过id进行修改
    @Override
    public void alterbyid(CourseDesign coursedesign) {
        coursedesignMapper.update(coursedesign);
    }
}
